//
//  TLComment.m
//  Coding_iOS
//
//  Created by taolei-mac on 2017/11/23.
//  Copyright © 2017年 com.lianchuan. All rights reserved.
//

#import "TLComment.h"
#import "TLHtmlMedia.h"

@implementation TLComment

+ (void)load
{
    [TLComment mj_setupReplacedKeyFromPropertyName:^NSDictionary *{
        
        return @{@"Id" : @"id"};
    }];
}

- (NSString *)created_at
{
    NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    NSDate *createDate = [_created_at dateWithTimeSp:_created_at];
    if(createDate.isThisYear){
        if(createDate.isToday){
            NSDateComponents *cmps = [createDate deltaWithNow];
            if (cmps.hour >= 1) { // 至少是1小时前发的
                return [NSString stringWithFormat:@"%ld小时前", cmps.hour];
            } else if (cmps.minute >= 1) { // 1~59分钟之前发的
                return [NSString stringWithFormat:@"%ld分钟前", cmps.minute];
            } else { // 1分钟内发的
                return @"刚刚";
            }
        }else if (createDate.isYesterday){
            fmt.dateFormat = @"昨天 HH:mm";
            return [fmt stringFromDate:createDate];
        }else{
            fmt.dateFormat = @"MM-dd HH:mm";
            return [fmt stringFromDate:createDate];
        }
    }else{
        
        fmt.dateFormat = @"yyyy-MM-dd";
        return [fmt stringFromDate:createDate];
    }
}

- (void)setContent:(NSString *)content
{
    _content = content;
    _htmlMedia = [TLHtmlMedia htmlMediaWithString:_content showType:MediaShowTypeNone];
    _content = _htmlMedia.contentDisplay;
}


@end
